<?php

namespace Trawind\Remotes\Repositories\Purchase\Procurement;

use Trawind\Remotes\BaseRepository;
use Trawind\Basics\Enums\ServiceDomain;
use Trawind\Remotes\Contracts\Repositories\Purchase\Procurement\PurchaseOrdersRepository;

/**
 * Class PurchaseOrdersRepositoryEloquent.
 *
 * @package namespace Trawind\Remotes\Repositories\Purchase\Procurement;
 */
class PurchaseOrdersRepositoryEloquent extends BaseRepository implements PurchaseOrdersRepository
{

    public $baseRoute='/purchase/purchase-orders';

    /**
     * PurchaseOrdersRepositoryEloquent constructor.
     */
    public function __construct()
    {
        $this->domain = ServiceDomain::PURCHASE_DOMAIN();
    }


    /**
     * Retrieve all data of repository
     *
     * @param array $columns
     *
     * @return mixed
     */
    public function all($columns = ['*'])
    {
        return $this->setUrl($this->baseRoute)->result();
    }


    /**
     * Find data by id
     *
     * @param       $id
     * @param array $columns
     *
     * @return mixed
     */
    public function find($id, $columns = ['*'])
    {
        return $this->setUrl($this->baseRoute.'/'.$id)->result();
    }

    /**
     * @inheritDoc
     */
    public function billAmountAndBillQuantity(array $params)
    {
        return $this->setUrl($this->baseRoute . '/billing')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }

    /**
     * @inheritDoc
     */
    public function saleQuantity(array $params)
    {
        return $this->setUrl($this->baseRoute . '/sale-quantity')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }

    public function autoReceive(array $params)
    {
        return $this->setUrl($this->baseRoute . '/auto-receive')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }

    public function paidAmount(array $params)
    {
        return $this->setUrl($this->baseRoute . '/paid')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }

    /**
     * @inheritDoc
     */
    public function refundAmount(array $params)
    {
        return $this->setUrl($this->baseRoute . '/refund-amount')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }

    public function receiptNoticeNotification(array $param)
    {
        return $this->setUrl($this->baseRoute . '/warehousing_notification')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }

    public function receiptNotification(array $param)
    {
        return $this->setUrl($this->baseRoute . '/receipt_quantity')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }


    public function payment(array $param)
    {
        return $this->setUrl($this->baseRoute . '/payment')
            ->setClientOptions(['form_params' => $param])
            ->result('POST');
    }

    public function changeQuantity($params)
    {
        return $this->setUrl($this->baseRoute . '/payment-quantity')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }

    public function prepayment($params)
    {
        return $this->setUrl($this->baseRoute . '/prepayment-quantity')
            ->setClientOptions(['form_params' => $params])
            ->result('POST');
    }


    /**
     * Save a new entity in repository
     *
     * @param array $attributes
     *
     * @return mixed
     */
    public function create(array $attributes)
    {
        return $this->setUrl($this->baseRoute)
            ->setClientOptions(['form_params' => $attributes])
            ->result('POST');
    }



    /**
     * Update a entity in repository by id
     *
     * @param array $attributes
     * @param       $id
     *
     * @return mixed
     */
    public function update(array $attributes, $id)
    {
        return $this->setUrl($this->baseRoute.'/'.$id)
            ->setClientOptions(['form_params' => $attributes])
            ->result('PUT');
    }
}
